<template>
  <div>
    <Shop
      :goodList="goodList"
      @sett="setFn"
      @sub="subFn"
      @del="delFn"
      @add="addFn"
    />
  </div>
</template>

<script>
import Shop from "./components/Shop.vue";
export default {
  components: {
    Shop,
  },
  data() {
    return {
      goodList: JSON.parse(localStorage.getItem("hh")),
    };
  },
  methods: {
    //全选
    setFn(val) {
      this.goodList.forEach((item) => (item.checked = val));
    },
    //删除
    delFn(index) {
      this.goodList.splice(index, 1);
    },
    addFn(index) {
      this.goodList[index].num++;
    },
    subFn(index) {
      if (this.goodList[index].num > 0) {
        this.goodList[index].num--;
      }
    },
  },
  watch: {
    goodList: {
      deep: true,
      handler() {
        localStorage.setItem("hh", JSON.stringify(this.goodList));
      },
    },
  },
};
</script>

<style>
</style>